package demo11;

import java.util.ArrayList;
import java.util.Scanner;

public class test1 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        while(true){
            System.out.println("请输入一个整数");
            String numStr = sc.nextLine();
            int num = Integer.parseInt(numStr);
            if (num >= 100 || num <= 0){
                System.out.println("当前数字不在1~100的范围中，请重新输入");
                continue;
            }else {
                list.add(num);
                int sum = getSum(list);
                if (sum >= 200 ){
                    System.out.println("输入的数据已经满足要求，程序结束");
                    break;
                }
            }

            for (int i = 0; i < list.size(); i++) {
                System.out.print(list.get(i)+" ");
            }
        }

    }

    private static int getSum(ArrayList<Integer> list) {
        int sum = 0;
        for (int i = 0; i < list.size(); i++) {
            sum += list.get(i);
        }
        return sum;
    }
}
